package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.content.CursorLoader;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.cloudsigns.factorymanager2.LoginActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.IView.INormalDailyFeedBackForInstallView;
import com.cloudsigns.factorymanager2.engineering.IView.IUnusualDailyFeedBackForInstallView;
import com.cloudsigns.factorymanager2.engineering.IView.IUnusualFeedBackForLogisticsCargoView;
import com.cloudsigns.factorymanager2.engineering.IView.IUnusualFeedBackForLogisticsDelayView;
import com.cloudsigns.factorymanager2.engineering.IView.IUnusualFeedBackForDamageView;
import com.cloudsigns.factorymanager2.engineering.IView.IUploadPhotoView;
import com.cloudsigns.factorymanager2.engineering.adapter.PopWindowAdapter;
import com.cloudsigns.factorymanager2.engineering.bean.DialogItemBean;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.bean.PhotoBean;
import com.cloudsigns.factorymanager2.engineering.customview.BottomListDialog;
import com.cloudsigns.factorymanager2.engineering.customview.SpinerPopWindow;
import com.cloudsigns.factorymanager2.engineering.presenter.NormalFeedBackForInstallPresenter;
import com.cloudsigns.factorymanager2.engineering.presenter.UnusualFeedBackForInstallPrsenter;
import com.cloudsigns.factorymanager2.engineering.presenter.UnusualFeedBackForLogisticsCargoPrsenter;
import com.cloudsigns.factorymanager2.engineering.presenter.UnusualFeedBackForLogisticsDelayPrsenter;
import com.cloudsigns.factorymanager2.engineering.presenter.UnusualFeedBackForDamagePrsenter;
import com.cloudsigns.factorymanager2.engineering.presenter.UploadPhotoPresenter;
import com.cloudsigns.factorymanager2.engineering.utils.PhotoUtil;
import com.cloudsigns.factorymanager2.event.EngineeringOrderDetailForTeamEvent;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.FileUtil;

import org.json.JSONArray;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Created by tony on 2018/4/10.
 */

public class AddEngineeringFeedBackActivity extends Activity implements IUploadPhotoView, IUnusualDailyFeedBackForInstallView, INormalDailyFeedBackForInstallView, IUnusualFeedBackForLogisticsDelayView, IUnusualFeedBackForLogisticsCargoView, IUnusualFeedBackForDamageView, View.OnClickListener, AdapterView.OnItemClickListener, BottomListDialog.OnItemDialogClick {
    private final String TAG = AddEngineeringFeedBackActivity.class.getSimpleName();
    private RelativeLayout rl_back;
    private TextView tv_title;
    private RadioGroup rg_feed_back_type;
    private RadioButton rb_normal_feedback, rb_unusual_feedback;
    private RadioButton cb_logistics_delay, cb_omit, cb_damage, cb_install_unusual, cb_normal_gongcheng, cb_normal_wuliu;
    private View rl_logistics_delay, rl_damage, rl_omit, rl_install_unusual, rl_normal_gongcheng, ll_norml_wuliu;
    private EditText edt_statu_feedback;
    private TextView btn_upload;
    private View rl_normal_feedback, rl_unusual_feedback;
    private EditText edt_delay_days;
    private TextView edt_impact;
    private EditText edt_omit_tent;
    private EditText edt_cargo_number;
    private TextView edt_cargo_impact;
    private EditText edt_unusual_adviece;
    private TextView edt_damage_product;
    private TextView edt_damage_unusual_adviece;
    private EditText edt_damage_number;
    private TextView edt_damage_impact;
    private EditText edt_unusual_reason_install, edt_unusual_adviece_install;
    private TextView edt_impact_install;
    private EditText edt_tv_feedback_content;
    private View rl_img_normal_feedback, rl_img_omit, rl_img_damange, rl_img_install;//rl_photographs_colon_bg2, rl_photographs_colon_bg3;
    private ImageView img_normal_feedback, img_omit, img_damage, img_install;//img2,img_add_2, img3, img_add_3;
    private List<String> imgUrlNormalList = new ArrayList<>();
    private List<String> imgUrlOmitList = new ArrayList<>();
    private List<String> imgUrlDamageList = new ArrayList<>();
    private List<String> imgUrlInstallList = new ArrayList<>();
    private String filePath;
    private final int NORMAL_FEEDBACK = 1;
    private final int UNSUAL_FEEDBACK = 2;
    private int feedBackType = NORMAL_FEEDBACK;

    private final int DELAY = 0;
    private final int OMIT = 1;
    private final int DAMAGE = 2;
    private final int INSTALL_UNUSUAL = 3;
    private int unusual_type = -1;
    private int damage_pop;
    private int DAMAGE_PRODUCT_POP = 1;
    private int DAMAGE_ADVICE_POP = 2;
    private int DAMAGE_IMPACT_POP = 3;
    private int ENGINEERING = 1;
    private int LOGISTIC = 2;
    private int normal_type = ENGINEERING;


    private int install_pop;
    private int INSTALL_ADVICE_POP = 1;
    private int INSTALL_IMPACT_POP = 2;
    private int omit_pop;
    private int OMIT_TENT_POP = 1;
    private int OMIT_ADVIECE_POP = 2;
    private int OMIT_IMPACT_POP = 3;

    private SpinerPopWindow<String> mSpinerPopWindow, delayDaysPopWindow, impactPopWindow, omitTentPopWindow, omitDvicePopWindow, productPopWindow, logisticPopWindow;
    private PopWindowAdapter popWindowAdapter, delayDaysPopWindowAdapter, impactPopWindowAdapter, omitTentAdapter, omitDviceAdapter, productAdapter, logisticAdapter;
    private List<String> popStrLs = new ArrayList<String>();
    private List<String> popDelayDaysStrLs = new ArrayList<String>();
    private List<String> popImpactStrLs = new ArrayList<String>();
    private List<String> omitTentStrLs = new ArrayList<String>();
    private List<String> omitDviceStrLs = new ArrayList<String>();
    private List<String> productStrLs = new ArrayList<String>();
    private List<String> logisticStrLs = new ArrayList<String>();

    private UploadPhotoPresenter uploadPhotoPresenter;
    private UnusualFeedBackForInstallPrsenter unusualFeedBackForInstallPrsenter;
    private UnusualFeedBackForLogisticsDelayPrsenter unusualFeedBackForLogisticsDelayPrsenter;
    private UnusualFeedBackForLogisticsCargoPrsenter unusualFeedBackForLogisticsCargoPrsenter;
    private UnusualFeedBackForDamagePrsenter unusualFeedBackForDamagePrsenter;
    private NormalFeedBackForInstallPresenter normalFeedBackForInstallPresenter;
    private EngineeringInstallationOrderBean engineeringInstallationOrderBean;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_add_engineering_feed_back);

        initView();
        tv_title.setText(getResources().getText(R.string.daily_feed_back));
        updateUI();
//        updateUnusualContent();
        updateNormalContent();

        if (null != getIntent()) {
            engineeringInstallationOrderBean = (EngineeringInstallationOrderBean) getIntent().getSerializableExtra(ConstantUtil.KEY_1);
        }


        logisticPopWindow = new SpinerPopWindow<String>(this, this);
        logisticAdapter = new PopWindowAdapter(this, TAG);
        logisticStrLs.add("要求日期到货");
        logisticStrLs.add("提前到货");
        logisticStrLs.add("在可接受范围内到货");

        logisticAdapter.setData(logisticStrLs);
        logisticPopWindow.setAdapter(logisticAdapter);

        mSpinerPopWindow = new SpinerPopWindow<String>(this, this);
        popWindowAdapter = new PopWindowAdapter(this, TAG);
        popStrLs.add("安装进行中");
        popStrLs.add("施工协调中");
        popStrLs.add("等待货物");
        popStrLs.add("完成");
        popWindowAdapter.setData(popStrLs);
        mSpinerPopWindow.setAdapter(popWindowAdapter);

        omitTentPopWindow = new SpinerPopWindow<String>(this, this);
        omitTentAdapter = new PopWindowAdapter(this, TAG);
        if (null != engineeringInstallationOrderBean) {
            List<ProductBean> productBeanList = engineeringInstallationOrderBean.getProductList();
            if (null != productBeanList) {
                for (ProductBean productBean : productBeanList) {
                    omitTentStrLs.add(productBean.getName());
                }
            }
        }
        if (omitTentStrLs.size() == 0) {
            omitTentStrLs.add("无产品");
        }


        omitTentAdapter.setData(omitTentStrLs);
        omitTentPopWindow.setAdapter(omitTentAdapter);

        omitDvicePopWindow = new SpinerPopWindow<String>(this, this);
        omitDviceAdapter = new PopWindowAdapter(this, TAG);
        omitDviceStrLs.add("重新发货");
        omitDviceStrLs.add("现场制作");
        omitDviceStrLs.add("现场修补");
        omitDviceStrLs.add("现场购买");


        omitDviceAdapter.setData(omitDviceStrLs);
        omitDvicePopWindow.setAdapter(omitDviceAdapter);

        delayDaysPopWindow = new SpinerPopWindow<String>(this, this);
        delayDaysPopWindowAdapter = new PopWindowAdapter(this, TAG);
        popDelayDaysStrLs.add("1");
        popDelayDaysStrLs.add("2");

        delayDaysPopWindowAdapter.setData(popDelayDaysStrLs);
        delayDaysPopWindow.setAdapter(delayDaysPopWindowAdapter);

        impactPopWindow = new SpinerPopWindow<String>(this, this);
        impactPopWindowAdapter = new PopWindowAdapter(this, TAG);
        popImpactStrLs.add("0");
        popImpactStrLs.add("1");
        popImpactStrLs.add("2");
        popImpactStrLs.add("3");
        popImpactStrLs.add("4");
        popImpactStrLs.add("5");
        popImpactStrLs.add("6");
        popImpactStrLs.add("7");


//        popImpactStrLs.add("无影响");
//        popImpactStrLs.add("调整1天");
//        popImpactStrLs.add("调整2天");
//        popImpactStrLs.add("调整3天");
//        popImpactStrLs.add("调整4天");
//        popImpactStrLs.add("调整5天");
//        popImpactStrLs.add("调整6天");
        impactPopWindowAdapter.setData(popImpactStrLs);
        impactPopWindow.setAdapter(impactPopWindowAdapter);

        productPopWindow = new SpinerPopWindow<String>(this, this);
        productAdapter = new PopWindowAdapter(this, TAG);
        if (null != engineeringInstallationOrderBean) {
            List<ProductBean> productBeanList = engineeringInstallationOrderBean.getProductList();
            if (null != productBeanList) {
                for (ProductBean productBean : productBeanList) {
                    productStrLs.add(productBean.getName());
                }
            }
        }
        if (productStrLs.size() == 0) {
            productStrLs.add("无产品");
        }


        productAdapter.setData(productStrLs);
        productPopWindow.setAdapter(productAdapter);


        uploadPhotoPresenter = new UploadPhotoPresenter(this);
        unusualFeedBackForInstallPrsenter = new UnusualFeedBackForInstallPrsenter(this);
        unusualFeedBackForLogisticsDelayPrsenter = new UnusualFeedBackForLogisticsDelayPrsenter(this);

        unusualFeedBackForLogisticsCargoPrsenter = new UnusualFeedBackForLogisticsCargoPrsenter(this);
        unusualFeedBackForDamagePrsenter = new UnusualFeedBackForDamagePrsenter(this);

        normalFeedBackForInstallPresenter = new NormalFeedBackForInstallPresenter(this);
    }

    private void initView() {
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        tv_title = (TextView) findViewById(R.id.tv_title);
        rg_feed_back_type = (RadioGroup) findViewById(R.id.rg_feed_back_type);
        rb_normal_feedback = (RadioButton) findViewById(R.id.rb_normal_feedback);
        rb_unusual_feedback = (RadioButton) findViewById(R.id.rb_unusual_feedback);
        edt_statu_feedback = (EditText) findViewById(R.id.edt_statu_feedback);
        btn_upload = (TextView) findViewById(R.id.btn_upload);
        rl_normal_feedback = findViewById(R.id.rl_normal_feedback);
        rl_unusual_feedback = findViewById(R.id.rl_unusual_feedback);
        rl_img_normal_feedback = findViewById(R.id.rl_img_normal_feedback);
        rl_img_omit = findViewById(R.id.rl_img_omit);
        rl_img_damange = findViewById(R.id.rl_img_damange);

        rl_img_install = findViewById(R.id.rl_img_install);

//        rl_photographs_colon_bg2 = findViewById(R.id.rl_photographs_colon_bg2);
//        rl_photographs_colon_bg3 = findViewById(R.id.rl_photographs_colon_bg3);

        img_omit = (ImageView) findViewById(R.id.img_omit);
        img_damage = (ImageView) findViewById(R.id.img_damage);
        img_install = (ImageView) findViewById(R.id.img_install);

        img_normal_feedback = (ImageView) findViewById(R.id.img_normal_feedback);
//        img_add_1 = findViewById(R.id.img_add_1);
//        img2 = findViewById(R.id.img2);
//        img_add_2 = findViewById(R.id.img_add_2);
//        img3 = findViewById(R.id.img3);
//        img_add_3 = findViewById(R.id.img_add_3);
        cb_logistics_delay = (RadioButton) findViewById(R.id.cb_logistics_delay);
        cb_omit = (RadioButton) findViewById(R.id.cb_omit);
        cb_damage = (RadioButton) findViewById(R.id.cb_damage);
        cb_install_unusual = (RadioButton) findViewById(R.id.cb_install_unusual);
        rl_logistics_delay = findViewById(R.id.rl_logistics_delay);
        rl_omit = findViewById(R.id.rl_omit);
        rl_damage = findViewById(R.id.rl_damage);
        rl_install_unusual = findViewById(R.id.rl_install_unusual);
        cb_normal_gongcheng = findViewById(R.id.cb_normal_gongcheng);
        cb_normal_wuliu = findViewById(R.id.cb_normal_wuliu);
        rl_normal_gongcheng = findViewById(R.id.rl_normal_gongcheng);
        ll_norml_wuliu = findViewById(R.id.ll_norml_wuliu);

        edt_delay_days = findViewById(R.id.edt_delay_days);
        edt_impact = findViewById(R.id.edt_impact);
        edt_tv_feedback_content = findViewById(R.id.edt_tv_feedback_content);

        edt_tv_feedback_content.setOnClickListener(this);

        edt_omit_tent = findViewById(R.id.edt_omit_tent);
        edt_cargo_number = findViewById(R.id.edt_cargo_number);
        edt_unusual_adviece = findViewById(R.id.edt_unusual_adviece);
        edt_cargo_impact = findViewById(R.id.edt_cargo_impact);
        edt_omit_tent.setOnClickListener(this);
        edt_unusual_adviece.setOnClickListener(this);
        edt_cargo_impact.setOnClickListener(this);

        edt_damage_product = (TextView) findViewById(R.id.edt_damage_product);
        edt_damage_number = (EditText) findViewById(R.id.edt_damage_number);
        edt_damage_unusual_adviece = (TextView) findViewById(R.id.edt_damage_unusual_adviece);
        edt_damage_impact = (TextView) findViewById(R.id.edt_damage_impact);
        edt_damage_impact.setOnClickListener(this);
        edt_damage_product.setOnClickListener(this);
        edt_damage_unusual_adviece.setOnClickListener(this);

        edt_unusual_reason_install = findViewById(R.id.edt_unusual_reason_install);
        edt_unusual_adviece_install = findViewById(R.id.edt_unusual_adviece_install);
        edt_impact_install = findViewById(R.id.edt_impact_install);
        edt_unusual_adviece_install.setOnClickListener(this);
        edt_impact_install.setOnClickListener(this);

        rl_back.setOnClickListener(this);
        btn_upload.setOnClickListener(this);
        edt_statu_feedback.setOnClickListener(this);
        rl_img_install.setOnClickListener(this);
        rl_img_damange.setOnClickListener(this);
        rl_img_normal_feedback.setOnClickListener(this);
        cb_logistics_delay.setOnClickListener(this);
        cb_omit.setOnClickListener(this);
        cb_damage.setOnClickListener(this);
        cb_install_unusual.setOnClickListener(this);
        cb_normal_gongcheng.setOnClickListener(this);
        cb_normal_wuliu.setOnClickListener(this);

//        edt_delay_days.setOnClickListener(this);
        edt_impact.setOnClickListener(this);
//        rl_photographs_colon_bg2.setOnClickListener(this);
//        rl_photographs_colon_bg3.setOnClickListener(this);

        rb_normal_feedback.setChecked(true);

        rg_feed_back_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int id) {
                if (id == R.id.rb_normal_feedback) {
                    feedBackType = NORMAL_FEEDBACK;
                    updateUI();

                } else if (id == R.id.rb_unusual_feedback) {
                    feedBackType = UNSUAL_FEEDBACK;
                    updateUI();
                }
            }
        });


    }

    private void updateUI() {
        if (feedBackType == NORMAL_FEEDBACK) {
            rl_normal_feedback.setVisibility(View.VISIBLE);
            rl_unusual_feedback.setVisibility(View.GONE);
        } else if (feedBackType == UNSUAL_FEEDBACK) {
            rl_normal_feedback.setVisibility(View.GONE);
            rl_unusual_feedback.setVisibility(View.VISIBLE);
        }
    }

    private void showListDialog() {
        DialogItemBean[] items = new DialogItemBean[]{
                new DialogItemBean(R.string.camera,
                        R.layout.dialog_list_item_normal),
                new DialogItemBean(R.string.gallary,
                        R.layout.dialog_list_item_normal),
                new DialogItemBean(R.string.cancel,
                        R.layout.dialog_list_item_normal)};
        BottomListDialog dialog = new BottomListDialog(this, Arrays.asList(items));
        dialog.setItemClick(this);
        dialog.show();
    }


    private void showStatuPopWindow() {
        mSpinerPopWindow.setWidth(edt_statu_feedback.getWidth());
        mSpinerPopWindow.showAsDropDown(edt_statu_feedback);
    }

    private void showDelayPopWindow() {
        delayDaysPopWindow.setWidth(edt_delay_days.getWidth());
        delayDaysPopWindow.showAsDropDown(edt_delay_days);
    }

    private void showImpactPopWindow() {
        if (unusual_type == DELAY) {
            impactPopWindow.setWidth(edt_impact.getWidth());
            impactPopWindow.showAsDropDown(edt_impact);
        }

        if (unusual_type == OMIT) {
            impactPopWindow.setWidth(edt_cargo_impact.getWidth());
            impactPopWindow.showAsDropDown(edt_cargo_impact);
        }

        if (unusual_type == DAMAGE) {
            impactPopWindow.setWidth(edt_damage_impact.getWidth());
            impactPopWindow.showAsDropDown(edt_damage_impact);
        }

        if (unusual_type == INSTALL_UNUSUAL) {
            impactPopWindow.setWidth(edt_impact_install.getWidth());
            impactPopWindow.showAsDropDown(edt_impact_install);
        }

    }

    private void showLogisticPopWindow() {
        logisticPopWindow.setWidth(edt_tv_feedback_content.getWidth());
        logisticPopWindow.showAsDropDown(edt_tv_feedback_content);
    }


    private void showOmitAdvicePopWindow() {
        if (unusual_type == OMIT) {
            omitDvicePopWindow.setWidth(edt_unusual_adviece.getWidth());
            omitDvicePopWindow.showAsDropDown(edt_unusual_adviece);
        } else if (unusual_type == DAMAGE) {
            omitDvicePopWindow.setWidth(edt_damage_unusual_adviece.getWidth());
            omitDvicePopWindow.showAsDropDown(edt_damage_unusual_adviece);
        } else if (unusual_type == INSTALL_UNUSUAL) {
            omitDvicePopWindow.setWidth(edt_unusual_adviece_install.getWidth());
            omitDvicePopWindow.showAsDropDown(edt_unusual_adviece_install);
        }

    }

    private void showProductPopWindow() {
        if (unusual_type == DAMAGE) {
            productPopWindow.setWidth(edt_damage_product.getWidth());
            productPopWindow.showAsDropDown(edt_damage_product);
        }
    }


    private void showOmitTentPopWindow() {
        if (unusual_type == OMIT) {
            omitTentPopWindow.setWidth(edt_omit_tent.getWidth());
            omitTentPopWindow.showAsDropDown(edt_omit_tent);
        }
    }

    private void updateUnusualContent() {
        if (unusual_type == DELAY) {
            cb_logistics_delay.setChecked(true);
            cb_omit.setChecked(false);
            cb_damage.setChecked(false);
            cb_install_unusual.setChecked(false);

            rl_logistics_delay.setVisibility(View.VISIBLE);
            rl_damage.setVisibility(View.GONE);
            rl_omit.setVisibility(View.GONE);
            rl_install_unusual.setVisibility(View.GONE);
        } else if (unusual_type == OMIT) {
            cb_logistics_delay.setChecked(false);
            cb_omit.setChecked(true);
            cb_damage.setChecked(false);
            cb_install_unusual.setChecked(false);

            rl_logistics_delay.setVisibility(View.GONE);
            rl_damage.setVisibility(View.GONE);
            rl_omit.setVisibility(View.VISIBLE);
            rl_install_unusual.setVisibility(View.GONE);
        } else if (unusual_type == DAMAGE) {
            cb_logistics_delay.setChecked(false);
            cb_omit.setChecked(false);
            cb_damage.setChecked(true);
            cb_install_unusual.setChecked(false);

            rl_logistics_delay.setVisibility(View.GONE);
            rl_damage.setVisibility(View.VISIBLE);
            rl_omit.setVisibility(View.GONE);
            rl_install_unusual.setVisibility(View.GONE);

        } else if (unusual_type == INSTALL_UNUSUAL) {
            cb_logistics_delay.setChecked(false);
            cb_omit.setChecked(false);
            cb_damage.setChecked(false);
            cb_install_unusual.setChecked(true);

            rl_logistics_delay.setVisibility(View.GONE);
            rl_damage.setVisibility(View.GONE);
            rl_omit.setVisibility(View.GONE);
            rl_install_unusual.setVisibility(View.VISIBLE);
        } else {
            cb_logistics_delay.setChecked(false);
            cb_omit.setChecked(false);
            cb_damage.setChecked(false);
            cb_install_unusual.setChecked(false);

            rl_logistics_delay.setVisibility(View.GONE);
            rl_damage.setVisibility(View.GONE);
            rl_omit.setVisibility(View.GONE);
            rl_install_unusual.setVisibility(View.GONE);
        }
    }

    private void updateNormalContent() {
        if (normal_type == ENGINEERING) {
            cb_normal_gongcheng.setChecked(true);
            cb_normal_wuliu.setChecked(false);

            rl_normal_gongcheng.setVisibility(View.VISIBLE);
            ll_norml_wuliu.setVisibility(View.GONE);

        } else if (normal_type == LOGISTIC) {
            cb_normal_gongcheng.setChecked(false);
            cb_normal_wuliu.setChecked(true);

            rl_normal_gongcheng.setVisibility(View.GONE);
            ll_norml_wuliu.setVisibility(View.VISIBLE);
        } else {
            cb_normal_gongcheng.setChecked(false);
            cb_normal_wuliu.setChecked(false);

            rl_normal_gongcheng.setVisibility(View.GONE);
            ll_norml_wuliu.setVisibility(View.GONE);
        }
    }

    private void submitFeedBack() {
        if (feedBackType == NORMAL_FEEDBACK) {
            normalFeedBackForInstallPresenter.submitNormalFeedBackForInstall();

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            switch (unusual_type) {
                case DELAY:
                    unusualFeedBackForLogisticsDelayPrsenter.submitUnusualFeedBackForLogisticsDelay();
                    break;
                case OMIT:
                    unusualFeedBackForLogisticsCargoPrsenter.submitUnusualFeedBackForLogisticsCargo();
                    break;
                case DAMAGE:
                    unusualFeedBackForDamagePrsenter.submitUnusualFeedBackForDamage();
                    break;
                case INSTALL_UNUSUAL:
                    unusualFeedBackForInstallPrsenter.submitUnusualFeedBackForInstall();
                    break;
            }

        }
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        if (feedBackType == NORMAL_FEEDBACK) {
            if (normal_type == ENGINEERING) {

                edt_statu_feedback.setText(popStrLs.get(i));
                edt_statu_feedback.setSelection(popStrLs.get(i).length());
            }

            if (normal_type == LOGISTIC) {

                edt_tv_feedback_content.setText(logisticStrLs.get(i));
                edt_tv_feedback_content.setSelection(logisticStrLs.get(i).length());
            }


        }

        if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusual_type == DELAY) {
                edt_impact.setText(popImpactStrLs.get(i));

//                if (UNUSUAL_CONTENT == DELAY_DAYS) {
//                    edt_delay_days.setText(popDelayDaysStrLs.get(i));
//
//                } else if (UNUSUAL_CONTENT == DELAY_IMPACT) {
//                    edt_impact.setText(1 + "");
////                    edt_impact.setText(popImpactStrLs.get(i));
////                    edt_impact.setSelection(popImpactStrLs.get(i).length());
//                }
            }

            if (unusual_type == OMIT) {
                if (omit_pop == OMIT_TENT_POP) {
                    edt_omit_tent.setText(omitTentStrLs.get(i));
                } else if (omit_pop == OMIT_ADVIECE_POP) {
                    edt_unusual_adviece.setText(omitDviceStrLs.get(i));
                } else if (omit_pop == OMIT_IMPACT_POP) {
                    edt_cargo_impact.setText(popImpactStrLs.get(i));
                }
            }

            if (unusual_type == DAMAGE) {
                if (damage_pop == DAMAGE_PRODUCT_POP)
                    edt_damage_product.setText(productStrLs.get(i));
                else if (damage_pop == DAMAGE_ADVICE_POP)
                    edt_damage_unusual_adviece.setText(omitDviceStrLs.get(i));
                else if (damage_pop == DAMAGE_IMPACT_POP)
                    edt_damage_impact.setText(popImpactStrLs.get(i));

            }

            if (unusual_type == INSTALL_UNUSUAL) {
                if (install_pop == INSTALL_ADVICE_POP)
                    edt_unusual_adviece_install.setText(omitDviceStrLs.get(i));
                else if (install_pop == INSTALL_IMPACT_POP)
                    edt_impact_install.setText(popImpactStrLs.get(i));
            }

        }


        if (null != mSpinerPopWindow)
            mSpinerPopWindow.dismiss();
        if (null != delayDaysPopWindow)
            delayDaysPopWindow.dismiss();
        if (null != omitTentPopWindow)
            omitTentPopWindow.dismiss();


        if (null != impactPopWindow)
            impactPopWindow.dismiss();
        if (null != omitDvicePopWindow)
            omitDvicePopWindow.dismiss();

        if (null != productPopWindow)
            productPopWindow.dismiss();

        if (null != logisticPopWindow)
            logisticPopWindow.dismiss();

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_upload:
                submitFeedBack();
                break;
            case R.id.rl_back:
                finish();
                break;
            case R.id.edt_statu_feedback:
                showStatuPopWindow();
                break;
            case R.id.edt_omit_tent:
                omit_pop = OMIT_TENT_POP;
                showOmitTentPopWindow();
                break;
            case R.id.edt_unusual_adviece:
                omit_pop = OMIT_ADVIECE_POP;
                showOmitAdvicePopWindow();
                break;
            case R.id.rl_img_normal_feedback:
//            case R.id.rl_img_omit:
            case R.id.rl_img_damange:
            case R.id.rl_img_install:

//            case R.id.rl_photographs_colon_bg2:
//            case R.id.rl_photographs_colon_bg3:
                showListDialog();
                break;
            case R.id.edt_delay_days:
//                UNUSUAL_CONTENT = DELAY_DAYS;
//                showDelayPopWindow();
                break;
            case R.id.edt_impact:
//                UNUSUAL_CONTENT = DELAY_IMPACT;
                showImpactPopWindow();
                break;
            case R.id.edt_cargo_impact:
                omit_pop = OMIT_IMPACT_POP;
                showImpactPopWindow();
                break;
            case R.id.edt_damage_impact:
                damage_pop = DAMAGE_IMPACT_POP;
                showImpactPopWindow();
                break;
            case R.id.edt_damage_product:
                damage_pop = DAMAGE_PRODUCT_POP;
                showProductPopWindow();
                break;
            case R.id.edt_damage_unusual_adviece:
                damage_pop = DAMAGE_ADVICE_POP;
                showOmitAdvicePopWindow();
                break;
            case R.id.edt_unusual_adviece_install:
                install_pop = INSTALL_ADVICE_POP;
                showOmitAdvicePopWindow();
                break;
            case R.id.edt_impact_install:
                install_pop = INSTALL_IMPACT_POP;
                showImpactPopWindow();
                break;
            case R.id.edt_tv_feedback_content:
                showLogisticPopWindow();
                break;
            case R.id.cb_logistics_delay:
                if (unusual_type == DELAY) {
                    cb_logistics_delay.setChecked(false);
                    unusual_type = -1;

                } else {
                    cb_logistics_delay.setChecked(true);
                    unusual_type = DELAY;

                }

                updateUnusualContent();

                break;
            case R.id.cb_omit:
                if (unusual_type == OMIT) {
                    cb_omit.setChecked(false);
                    unusual_type = -1;
                } else {
                    cb_omit.setChecked(true);
                    unusual_type = OMIT;

                }
                updateUnusualContent();
                break;
            case R.id.cb_damage:
                if (unusual_type == DAMAGE) {
                    cb_damage.setChecked(false);
                    unusual_type = -1;

                } else {
                    cb_damage.setChecked(true);
                    unusual_type = DAMAGE;

                }
                updateUnusualContent();
                break;
            case R.id.cb_install_unusual:
                if (unusual_type == INSTALL_UNUSUAL) {
                    cb_install_unusual.setChecked(false);
                    unusual_type = -1;

                } else {
                    cb_install_unusual.setChecked(true);
                    unusual_type = INSTALL_UNUSUAL;

                }
                updateUnusualContent();
                break;
            case R.id.cb_normal_gongcheng:
                if (normal_type == ENGINEERING) {
                    cb_normal_gongcheng.setChecked(false);
                    normal_type = -1;
                } else {
                    cb_normal_gongcheng.setChecked(true);
                    normal_type = ENGINEERING;
                }

                updateNormalContent();
                break;
            case R.id.cb_normal_wuliu:
                if (normal_type == LOGISTIC) {
                    cb_normal_wuliu.setChecked(false);
                    normal_type = -1;
                } else {
                    cb_normal_wuliu.setChecked(true);
                    normal_type = LOGISTIC;
                }

                updateNormalContent();
                break;
        }
    }

    @Override
    public void onItemDialogClick(DialogItemBean item) {

        switch (item.getmTextId()) {
            case R.string.camera: {
//                File file = new File(PhotoUtil.CAMERA_CACHE);
//                if (file.isDirectory() && file.exists()) {
//                    File files[] = file.listFiles();
//                    for (int i = 0; i < files.length; i++) {
//                        File tmp = files[i];
//                        tmp.delete();
//                    }
//                }

                PhotoUtil.startCamear(AddEngineeringFeedBackActivity.this, null);
                break;
            }
            case R.string.gallary: {
                PhotoUtil.startGallery(AddEngineeringFeedBackActivity.this, null);
                break;
            }
            default:
                break;
        }

    }


    @Override
    protected void onDestroy() {
        if (null != mSpinerPopWindow) {
            mSpinerPopWindow.dismiss();
            mSpinerPopWindow = null;
        }


        if (null != delayDaysPopWindow) {
            delayDaysPopWindow.dismiss();
            delayDaysPopWindow = null;
        }

        if (null != impactPopWindow) {
            impactPopWindow.dismiss();
            impactPopWindow = null;
        }


        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (null != data) {

            switch (requestCode) {

                case PhotoUtil.CAMERA:
                    if (resultCode == RESULT_OK) {
                        File picture = new File(PhotoUtil.filePath);
                        if (!picture.exists()) {
                            picture = new File(PhotoUtil.filePath);
                        }

                        filePath = PhotoUtil.CAMERA_SEVER + picture.getName();
                        filePath = PhotoUtil.imageCompressionAndSave(picture.getAbsolutePath(), filePath);
                        //override(100, 100)

                        if (feedBackType == NORMAL_FEEDBACK) {
                            Glide.with(this).load(picture).asBitmap().into(img_normal_feedback);
                        } else if (feedBackType == UNSUAL_FEEDBACK) {
                            switch (unusual_type) {
                                case DELAY:
                                    break;
                                case OMIT:
//                                Glide.with(this).load(picture).asBitmap().into(img_omit);
                                    break;
                                case DAMAGE:
                                    Glide.with(this).load(picture).asBitmap().into(img_damage);
                                    break;
                                case INSTALL_UNUSUAL:
                                    Glide.with(this).load(picture).asBitmap().into(img_install);
                                    break;
                            }

                        }


//                filePath = PhotoUtil.filePath;
                        uploadPhotoPresenter.uploadPhtoto();
//                if (picture.exists()) {
//                    picture.delete();
//                }
//                PhotoUtil.startPhotoZoom(AddEngineeringFeedBackActivity.this, Uri.fromFile(picture), PhotoUtil.PICTURE_HEIGHT, PhotoUtil.PICTURE_WIDTH);


                    }

                    break;

                case PhotoUtil.GALLERY:
                    if (resultCode == RESULT_OK) {
                        if (feedBackType == NORMAL_FEEDBACK) {
                            Glide.with(this).load(data.getData()).asBitmap().into(img_normal_feedback);

                        } else if (feedBackType == UNSUAL_FEEDBACK) {
                            switch (unusual_type) {
                                case DELAY:
                                    break;
                                case OMIT:
//                                    Glide.with(this).load(data.getData()).asBitmap().into(img_omit);

                                    break;
                                case DAMAGE:
                                    Glide.with(this).load(data.getData()).asBitmap().into(img_damage);

                                    break;
                                case INSTALL_UNUSUAL:
                                    Glide.with(this).load(data.getData()).asBitmap().into(img_install);

                                    break;
                            }

                        }

                        String path = FileUtil.getRealPathFromURI(this, Uri.parse(data.getData() + ""));
                        File f = new File(path);
                        filePath = PhotoUtil.CAMERA_SEVER + f.getName();
                        filePath = PhotoUtil.imageCompressionAndSave(path, filePath);
//                    filePath = data.getData() + "";
                        uploadPhotoPresenter.uploadPhtoto();
//                    if (f.exists()) {
//                        f.delete();
//                    }
                    }
                    break;
                case PhotoUtil.PHOTORESOULT:
                    break;
            }
        }

        super.onActivityResult(requestCode, resultCode, data);
    }


    @Override
    public String getFilePath() {
        return filePath;
    }


    @Override
    public void upLoadPhotoSuccessed(String uri) {
        if (feedBackType == NORMAL_FEEDBACK) {
            imgUrlNormalList.clear();
            imgUrlNormalList.add(uri);
        } else if (feedBackType == UNSUAL_FEEDBACK) {
            switch (unusual_type) {
                case DELAY:
                    break;
                case OMIT:
                    imgUrlOmitList.clear();
                    imgUrlOmitList.add(uri);
                    break;
                case DAMAGE:
                    imgUrlDamageList.clear();
                    imgUrlDamageList.add(uri);
                    break;
                case INSTALL_UNUSUAL:
                    imgUrlInstallList.clear();
                    imgUrlInstallList.add(uri);
                    break;
            }

        }

    }

    @Override
    public void upLoadPhotoFailed(String desc) {
//        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }

    @Override
    public String getAdvice() {
        if (unusual_type == OMIT)
            return edt_unusual_adviece.getText().toString().trim();
        else if (unusual_type == DAMAGE)
            return edt_damage_unusual_adviece.getText().toString().trim();
        else if (unusual_type == INSTALL_UNUSUAL)
            return edt_unusual_adviece_install.getText().toString().trim();
        return "";
    }

    @Override
    public String getId() {
        if (null != engineeringInstallationOrderBean)
            return engineeringInstallationOrderBean.getId();
        return "";
    }

    @Override
    public List<String> getImgUrlList() {

        if (feedBackType == NORMAL_FEEDBACK) {
            return imgUrlNormalList;

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusual_type == OMIT) {
                return imgUrlOmitList;
            } else if (unusual_type == DAMAGE) {
                return imgUrlDamageList;
            } else if (unusual_type == INSTALL_UNUSUAL) {
                return imgUrlInstallList;
            }
        }

        return null;
    }

    @Override
    public String getItemId() {
        return null;
    }

    @Override
    public CommonEnum.EngineeringORderCategory getType() {
//        if(null != engineeringInstallationOrderBean)
//            return  engineeringInstallationOrderBean.getCategory();
        return CommonEnum.EngineeringORderCategory.INSTALL;
    }

    @Override
    public int getUnusualDays() {
        int day = 0;
        if (unusual_type == DELAY) {
            String str = edt_impact.getText().toString().trim();
            if (null != str || !TextUtils.isEmpty(str))
                day = Integer.parseInt(str);
        }

        if (unusual_type == OMIT) {
            String str = edt_cargo_impact.getText().toString().trim();
            if (null != str || !TextUtils.isEmpty(str))
                day = Integer.parseInt(str);
        }

        if (unusual_type == DAMAGE) {
            String str = edt_damage_impact.getText().toString().trim();
            if (null != str || !TextUtils.isEmpty(str))
                day = Integer.parseInt(str);
        }

        if (unusual_type == INSTALL_UNUSUAL) {
            String str = edt_impact_install.getText().toString().trim();
            if (null != str || !TextUtils.isEmpty(str))
                day = Integer.parseInt(str);
        }


        return day;
    }

    @Override
    public String getcontent() {
        return edt_tv_feedback_content.getText().toString().trim();
    }

    @Override
    public String getfeedbackContentRemark() {
        return null;
    }

    @Override
    public CommonEnum.NormalSubType getfeedbackSubType() {
        if (normal_type == ENGINEERING) {
            return  CommonEnum.NormalSubType.CONSTRUCT;

        } else if (normal_type == LOGISTIC) {
            return  CommonEnum.NormalSubType.LOGISTICS;

        }
        return null;
    }

    @Override
    public void submitUnusualFeedBackForDamageSunccessed() {
        Toast.makeText(this, "物流货损反馈成功！", Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post(new EngineeringOrderDetailForTeamEvent());
        finish();
    }

    @Override
    public void submitUnusualFeedBackForDamageFailed(String desc) {
        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }

    @Override
    public String getUnusualReason() {
        return edt_unusual_reason_install.getText().toString().trim();
    }

    @Override
    public void submitUnusualFeedBackForLogisticsCargoSuccessed() {
        Toast.makeText(this, "物流漏货反馈成功！", Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post(new EngineeringOrderDetailForTeamEvent());
        finish();
    }

    @Override
    public void submitUnusualFeedBackForLogisticsCargoFailed(String desc) {
        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }

    @Override
    public String getStatus() {
        return edt_statu_feedback.getText().toString().trim();

    }

    @Override
    public void submitUnusualFeedBackForLogisticsDelaySuccessed() {
        Toast.makeText(this, "物流延误反馈成功！", Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post(new EngineeringOrderDetailForTeamEvent());
        finish();
    }

    @Override
    public void submitUnusualFeedBackForLogisticsDelayFailed(String desc) {
        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }

    @Override
    public String getOmitContent() {
        return edt_omit_tent.getText().toString().trim();
    }

    @Override
    public int getOmitNumber() {
        String str = edt_cargo_number.getText().toString().trim();
        if (null != str && !TextUtils.isEmpty(str))
            return Integer.parseInt(str);
        return 0;
    }

    @Override
    public void submitUnusualFeedBackForInstallViewSuccessed() {
        Toast.makeText(this, "安装异常反馈成功！", Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post(new EngineeringOrderDetailForTeamEvent());
        finish();
    }

    @Override
    public void submitUnusualFeedBackForInstallViewFailed(String desc) {
        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }


    @Override
    public void submitNormalFeedBackForInstallSuccessed() {
        Toast.makeText(this, "正常反馈成功！", Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post(new EngineeringOrderDetailForTeamEvent());
        finish();
    }

    @Override
    public void submitNormalFeedBackForInstallFailed(String desc) {
        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }

    @Override
    public int getDelayDays() {
        int day = 0;
        if (unusual_type == DELAY) {
            String str = edt_delay_days.getText().toString().trim();
            if (null == str || TextUtils.isEmpty(str)) {

            } else {
                day = Integer.parseInt(str);

            }
        }


        return day;
    }

    @Override
    public int getDamageNumber() {
        String str = edt_damage_number.getText().toString().trim();
        if (null != str && !TextUtils.isEmpty(str))
            return Integer.parseInt(str);
        return 0;
    }

    @Override
    public String getDamageProduct() {
        return edt_damage_product.getText().toString().trim();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
